{% extends 'qna/base.html' %}
{% load static %}

{% block head %}
<link href="{% static 'qna/css/question.css' %}" type="text/css" rel="stylesheet">
<link href="{% static 'qna/css/page.css' %}" type="text/css" rel="stylesheet">
{% endblock %}

{% block title %}
Вопросы
{% endblock %}

{% block content %}
{% if user.is_authenticated %}
    <a href="/new_question/" class="add"><div class="plus"><p>Добавить вопрос</p><span></span></div></a>
{% endif %}

{% spaceless %}
<div id="content">{% if question.first %}{% for questions in question %}
            <div class="question" ><a href="detail/{{ questions.id }}" name="{{ questions.id }}">
                <div class="top">
                    <p class="titel">{{ questions.titel|safe }}</p>
                    <p class="name">Создана: {{ questions.name }}</p>
                </div>
                <p class="text">{{ questions.question | safe | truncatechars:40 }}</p>
            </a>
            </div>
        {% endfor %}
    {% else %}
        <div class="question"><p class="name">Создана: Аноним</p><p class="text">Пока что вопросов нет, но ты можешь задать свой!</p></div>
    {% endif %}

</div>
{% endspaceless %}

<nav class="list-pages"> 
    <ul>
        {% if page_obj.has_previous %}
        <li class="page-num">
            <a href="?page={{ page_obj.previous_page_number }}">&lt;</a>
        </li>
        {% endif %}
        {% for p in page_obj.paginator.page_range %}
                   {% if page_obj.number == p %}
        <li class="page-num page-num-selected">{{ p }}</li>
                   {% elif p >= page_obj.number|add:-2 and p <= page_obj.number|add:2  %}
        <li class="page-num">
            <a href="?page={{ p }}">{{ p }}</a>
        </li>
                   {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
        <li class="page-num">
                <a href="?page={{ page_obj.next_page_number }}">&gt;</a>
        </li>
{% endif %}
    </ul>
</nav>
{% endblock %}
